/*
 * LayoutRenderCustomizer.java
 *
 * Created on January 25, 2009, 11:49 AM
 */

package org.netbeans.modules.web.stripes.palette.items;

import org.netbeans.modules.web.stripes.palette.CodeSnippet;
import org.netbeans.modules.web.stripes.palette.CodeSnippetCustomizer;
import javax.swing.text.JTextComponent;

import org.netbeans.modules.web.stripes.palette.StripesPaletteUtilities;
import org.netbeans.modules.web.stripes.util.StringUtils;
import org.netbeans.modules.web.stripes.util.browse.BrowseDialogs;

/**
 *
 * @author  Josef Sustacek
 */
public class LayoutRenderCustomizer extends CodeSnippetCustomizer {

    private JTextComponent target;
    
    /** Creates new form LayoutRenderCustomizer */
    public LayoutRenderCustomizer(CodeSnippet codeSnippet, JTextComponent target) {
        super(codeSnippet);
        
        this.target = target;
        
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();
        jLabel1 = new javax.swing.JLabel();
        nameText = new javax.swing.JTextField();
        browseButton = new javax.swing.JButton();

        jLabel1.setText(org.openide.util.NbBundle.getMessage(LayoutRenderCustomizer.class, "LayoutRenderCustomizer.jLabel1.text")); // NOI18N

        nameText.setText(org.openide.util.NbBundle.getMessage(LayoutRenderCustomizer.class, "LayoutRenderCustomizer.nameText.text")); // NOI18N

        browseButton.setText(org.openide.util.NbBundle.getMessage(LayoutRenderCustomizer.class, "LayoutRenderCustomizer.browseButton.text")); // NOI18N
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(browseButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browseButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    String selectedJspPath = BrowseDialogs.jspSourcesDialog(
            StripesPaletteUtilities.getProject(target), this);

    if(!StringUtils.nullOrEmpty(selectedJspPath)){
        nameText.setText(selectedJspPath);
    }
}//GEN-LAST:event_browseButtonActionPerformed

    @Override
    protected void evaluateInput() {
        codeSnippet.setProperty(LayoutRender.NAME, nameText.getText());
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browseButton;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField nameText;
    // End of variables declaration//GEN-END:variables

}
